/*     */ package com.zimbra.cs.milter;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.PermissionCache;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.server.NioConnection;
/*     */ import com.zimbra.cs.server.NioHandler;
/*     */ import com.zimbra.cs.server.NioServer;
/*     */ import com.zimbra.cs.server.Server;
/*     */ import com.zimbra.cs.server.ServerConfig;
/*     */ import org.apache.mina.core.session.IoSession;
/*     */ import org.apache.mina.filter.codec.ProtocolCodecFactory;
/*     */ import org.apache.mina.filter.codec.ProtocolDecoder;
/*     */ import org.apache.mina.filter.codec.ProtocolEncoder;
/*     */ import sun.misc.Signal;
/*     */ import sun.misc.SignalHandler;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class MilterServer
/*     */   extends NioServer
/*     */   implements Server
/*     */ {
/*  40 */   private final ProtocolDecoder decoder = new NioMilterDecoder();
/*  41 */   private final ProtocolEncoder encoder = new NioMilterEncoder();
/*     */   
/*     */   public MilterServer(ServerConfig config) throws ServiceException {
/*  44 */     super(config);
/*  45 */     registerMBean(getName());
/*     */   }
/*     */   
/*     */   public String getName()
/*     */   {
/*  50 */     return "MilterServer";
/*     */   }
/*     */   
/*     */   public NioHandler createHandler(NioConnection conn)
/*     */   {
/*  55 */     return new MilterHandler(conn);
/*     */   }
/*     */   
/*     */   protected ProtocolCodecFactory getProtocolCodecFactory()
/*     */   {
/*  60 */     new ProtocolCodecFactory()
/*     */     {
/*     */       public ProtocolDecoder getDecoder(IoSession session) {
/*  63 */         return MilterServer.this.decoder;
/*     */       }
/*     */       
/*     */       public ProtocolEncoder getEncoder(IoSession session)
/*     */       {
/*  68 */         return MilterServer.this.encoder;
/*     */       }
/*     */     };
/*     */   }
/*     */   
/*     */   public MilterConfig getConfig()
/*     */   {
/*  75 */     return (MilterConfig)super.getConfig();
/*     */   }
/*     */   
/*     */   public Log getLog()
/*     */   {
/*  80 */     return ZimbraLog.milter;
/*     */   }
/*     */   
/*     */   private static final class MilterShutdownHook extends Thread {
/*     */     private final MilterServer server;
/*     */     
/*     */     public MilterShutdownHook(MilterServer server) {
/*  87 */       this.server = server;
/*     */     }
/*     */     
/*     */     public void run()
/*     */     {
/*  92 */       ZimbraLog.milter.info("Shutting down milter server");
/*  93 */       this.server.stop();
/*     */     }
/*     */   }
/*     */   
/*     */   public static void main(String[] args) {
/*     */     try {
/*  99 */       Provisioning prov = Provisioning.getInstance();
/* 100 */       if ((prov instanceof LdapProv)) {
/* 101 */         ((LdapProv)prov).waitForLdapServer();
/*     */       }
/*     */       
/* 104 */       MilterConfig config = new MilterConfig();
/* 105 */       MilterServer server = new MilterServer(config);
/*     */       
/*     */ 
/* 108 */       ClearCacheSignalHandler.register();
/*     */       
/* 110 */       MilterShutdownHook shutdownHook = new MilterShutdownHook(server);
/* 111 */       Runtime.getRuntime().addShutdownHook(shutdownHook);
/*     */       
/* 113 */       ZimbraLog.milter.info("Starting milter server");
/* 114 */       server.start();
/*     */     } catch (ServiceException e) {
/* 116 */       ZimbraLog.milter.error("Unable to start milter server", e);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static final class ClearCacheSignalHandler
/*     */     implements SignalHandler
/*     */   {
/*     */     public void handle(Signal signal)
/*     */     {
/* 132 */       ZimbraLog.milter.info("Received Signal: %s", new Object[] { signal.getName() });
/* 133 */       ZimbraLog.milter.info("Begin ACL cache invalidation");
/* 134 */       PermissionCache.invalidateAllCache();
/* 135 */       ZimbraLog.milter.info("ACL cache successfully cleared");
/*     */     }
/*     */     
/*     */ 
/*     */     public static void register()
/*     */     {
/*     */       try
/*     */       {
/* 143 */         Signal hup = new Signal("CONT");
/* 144 */         ClearCacheSignalHandler handler = new ClearCacheSignalHandler();
/*     */         
/* 146 */         Signal.handle(hup, handler);
/* 147 */         ZimbraLog.milter.info("Registered signal handler: %s(%d)", new Object[] { hup.getName(), Integer.valueOf(hup.getNumber()) });
/*     */       }
/*     */       catch (Throwable t)
/*     */       {
/* 151 */         ZimbraLog.milter.error("Unabled to register signal handler CONT/19 and script refresh will not work", t);
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/milter/MilterServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */